package com.alibaba.dubbo.remoting;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Map;

import com.alibaba.dubbo.common.extension.SPI;
import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.remoting.buffer.ChannelBufferInputStream;

/**
 * 通道过滤器，用来实现黑名单、白名单
 * @author kingbo.ruan
 *
 */
@SPI
public interface Interceptor {
	/**
	 * 通道连接是调用
	 * @param 远程地址
	 * @return
	 */
	public boolean acceptAfterConnected(InetAddress remoteAddress);
	
	/**
	 * 通道头信息到达，
	 * @param channel
	 * @param total  包含body和header的全部长度
	 * @param body   body长度
	 * @return
	 */
	public boolean acceptAfterHead(InetAddress remoteAddress, int total, int body);
	
	/**
	 * 通道有附件信息到达
	 * @param channel
	 * @param attachments
	 * @return
	 */
	public boolean acceptAfterDecodeHeader(InetAddress remoteAddress, Map<String, String> headers, int body);
	/**
	 * 通道附件和数据解码成功时调用
	 * @param channel
	 * @param attachments
	 * @param value
	 * @return
	 */
	public boolean acceptAfterDecodeBody(InetAddress remoteAddress, Map<String, String> headers,  RemoteCalling calling);
	/**
	 * 应答之前
	 * @param channel
	 * @param headers
	 * @param value
	 * @return
	 */
	public boolean acceptBeforeEncodeBody(InetAddress remoteAddress, Map<String, String> headers);
	/**
	 * 加密header之前
	 * @param remoteAddress
	 * @param headers
	 * @return
	 */
	public boolean acceptBeforeEncodeHeader(InetAddress remoteAddress, Map<String, String> headers);
}
